<template>
    <div>
        <el-dialog v-model="isup" title="驳回原因" width="580">
            <el-input v-model="Causeofrejection" maxlength="50" show-word-limit type="textarea" placeholder="请输入备注" />
            <template #footer>
                <span class="flex items-center justify-center">
                    <el-button @click="onCancel">取消</el-button>
                    <el-button type="primary" class="bg-#0256ff" @click="OnSure">
                        确定
                    </el-button>
                </span>
            </template>
        </el-dialog>
    </div>
</template>

<script setup lang="ts">
import { getbulletpayrollapi, getelectronicvisaauditapi, geteverydayinsuranceauditapi, getlongtimeinsuranceauditapi, getmessageauditapi } from '@/api/api'
import { ElMessage } from 'element-plus'
import { ref, watch } from 'vue'
const props = defineProps({
    show: {
        type: Boolean,
        default: false
    },
    type: {
        type: String,
        default: ''
    },
    detail: {
        type: Object,
        default: () => { }
    }
})
const emits = defineEmits(['update:show', 'success'])
const isup = ref(false)
const Causeofrejection = ref<string>('')
const onCancel = () => {
    isup.value = false
    emits('update:show', false)
}
const OnSure = async () => {
    if (Causeofrejection.value === '') {
        ElMessage.warning('请输入驳回原因')
        return
    }
    if (props.type === 'bull') {
        await getbulletpayrollapi({
            id: props.detail.id,
            companyId: props.detail.companyId,
            status: 2,
            payMode: props.detail.paymode,
            remark: Causeofrejection.value,
            receiptId: props.detail.receptid
        })
    } else if (props.type === 'ele') {
        await getelectronicvisaauditapi({
            id: props.detail.id,
            companyId: props.detail.companyId,
            status: 2,
            payMode: props.detail.paymode,
            remark: Causeofrejection.value,
            receiptId: props.detail.receptid
        })
    } else if (props.type === 'long') {
        await getlongtimeinsuranceauditapi({
            operateFlag: 2,
            receiptId: props.detail.receptid,
            payMode: props.detail.paymode ?? '',
            remark: Causeofrejection.value,
            companyId: props.detail.companyId,
            id: props.detail.id
        })
    } else if (props.type === 'every') {
        await geteverydayinsuranceauditapi({
            operateFlag: 2,
            receiptId: props.detail.receptid,
            payMode: props.detail.paymode,
            remark: Causeofrejection.value,
            companyId: props.detail.companyId,
            id: props.detail.id
        })
    } else if (props.type === 'message') {
        await getmessageauditapi({
            operateFlag: 2,
            receiptId: props.detail.receptid,
            payMode: props.detail.paymode,
            remark: Causeofrejection.value,
            companyId: props.detail.companyId,
            id: props.detail.id
        })
    }
    isup.value = false
    emits('success')
}
watch(
    () => props.show, (newval) => {
        isup.value = newval
        if (newval) {
            Causeofrejection.value = ''
        }
    }
)
watch(isup, (newval) => {
    emits('update:show', newval)
})
</script>

<style scoped></style>